<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:DentalGUIHelper;assembly=DentalConfig">

    <!-- ========================= -->
    <!--        Converters         -->
    <!-- ========================= -->
    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>

    <!-- ============================== -->
    <!--   ContentAndTextButton Style   -->
    <!-- ============================== -->
    <Style TargetType="{x:Type local:ImageAndTextButton}">
        <Setter Property="Background" Value="{DynamicResource ImageAndTextButtonBackground}" />
        <Setter Property="Foreground" Value="{DynamicResource ImageAndTextButtonForeground}" />
        <Setter Property="BorderBrush" Value="{DynamicResource ImageAndTextButtonBorderBrush}" />
        <Setter Property="BorderThickness" Value="2" />
        <Setter Property="Width" Value="Auto" />
        <Setter Property="Height" Value="Auto" />
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="TextDock" Value="Right" />
        <Setter Property="TextMargin" Value="5" />
        <Setter Property="ContentWidth" Value="Auto" />
        <Setter Property="ContentHeight" Value="Auto" />     
        <Setter Property="FontSize" Value="18"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:ImageAndTextButton}">
                    <DockPanel Background="Transparent" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                        <!-- Content (= Image) with circle around it -->
                        <Grid x:Name="grid" Background="#02FFFFFF" Margin="{TemplateBinding Padding}" DockPanel.Dock="Left" 
                              Visibility="{TemplateBinding ShowContent, Converter={StaticResource BooleanToVisibilityConverter}}">
                            <Viewbox Width="{TemplateBinding ContentWidth}" Height="{TemplateBinding ContentHeight}">
                                <Grid>
                                    <!-- Background -->
                                    <Ellipse x:Name="ellipsebg"
                                         Fill="{TemplateBinding Foreground}"
                                         StrokeThickness="0"
                                         Opacity="0"
                                         VerticalAlignment="Stretch"
                                         Width="56"
                                         Height="56" />

                                    <!-- Content, e.g. Icon -->
                                    <Rectangle x:Name="rectangle"  Width="{DynamicResource ContentAndTextButtonIconWidth}" Height="{DynamicResource ContentAndTextButtonIconWidth}" Fill="{TemplateBinding Foreground}">
                                        <Rectangle.OpacityMask>
                                            <VisualBrush>
                                                <VisualBrush.Visual>
                                                    <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                                                      VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                                </VisualBrush.Visual>
                                            </VisualBrush>
                                        </Rectangle.OpacityMask>
                                    </Rectangle>

                                    <!-- Foreground -->
                                    <Ellipse x:Name="ellipse"
                                         Stroke="{TemplateBinding Foreground}"
                                         StrokeThickness="{Binding Path=BorderThickness.Left, RelativeSource={RelativeSource TemplatedParent}}"
                                         VerticalAlignment="Stretch"
                                         Width="56"
                                         Height="56" />
                                </Grid>
                            </Viewbox>
                        </Grid>

                        <!-- Text -->
                        <Grid Name="textContainer"  VerticalAlignment="Center" Margin="{TemplateBinding TextMargin}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <TextBlock x:Name="PART_TextBlockMain" Text="{TemplateBinding Text}" Foreground="{TemplateBinding Foreground}"
                                       FontSize="{TemplateBinding FontSize}" FontFamily="{DynamicResource BoldFontFamily}"
                                    TextWrapping="WrapWithOverflow"
                                   Visibility="{TemplateBinding ShowText, Converter={StaticResource BooleanToVisibilityConverter}}"
                                   HorizontalAlignment="Left" VerticalAlignment="Center" />
                            <TextBlock Grid.Row="1"  x:Name="PART_TextBlockDescription" Text="{TemplateBinding Description}" Foreground="{DynamicResource ContentAndTextButtonDescriptionTextBrush}"
                                   FontSize="{DynamicResource NormalFontSize}"  FontFamily="{DynamicResource BoldFontFamily}" Margin="0 2 0 0"
                                   TextWrapping="WrapWithOverflow"
                                   Visibility="{TemplateBinding ShowDescription, Converter={StaticResource BooleanToVisibilityConverter}}"
                                   HorizontalAlignment="Left" VerticalAlignment="Center" />

                        </Grid>
                    </DockPanel>

                    <ControlTemplate.Triggers>
                        <Trigger Property="TextDock" Value="Right">
                            <Setter TargetName="grid" Property="DockPanel.Dock" Value="Left" />
                            <Setter TargetName="textContainer" Property="HorizontalAlignment" Value="Left" />
                        </Trigger>
                        <Trigger Property="TextDock" Value="Left">
                            <Setter TargetName="grid" Property="DockPanel.Dock" Value="Right" />
                            <Setter TargetName="textContainer" Property="HorizontalAlignment" Value="Right" />
                        </Trigger>
                        <Trigger Property="TextDock" Value="Top">
                            <Setter TargetName="grid" Property="DockPanel.Dock" Value="Bottom" />
                            <Setter TargetName="textContainer" Property="HorizontalAlignment" Value="Center" />
                        </Trigger>
                        <Trigger Property="TextDock" Value="Bottom">
                            <Setter TargetName="grid" Property="DockPanel.Dock" Value="Top" />
                            <Setter TargetName="textContainer" Property="HorizontalAlignment" Value="Center" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="ellipsebg" Property="Opacity" Value="0.2" />
                            <Setter TargetName="PART_TextBlockMain" Property="Opacity" Value="0.6" />
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter TargetName="ellipsebg" Property="Opacity" Value="1" />
                            <Setter TargetName="rectangle" Property="Fill" Value="{Binding Path=Background, RelativeSource={RelativeSource TemplatedParent}}" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Opacity" Value="0.5" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>